package drds.configuration.common;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 最常用的判断工具类 字符串为空判断和集合元素判断。该类不允许添加其他方法。
 *
 * @author caozhenghui@drds.team<330937205@qq.com>
 */
public class MyUtil {
    //
    public static boolean isNull(String string) {
        if (string == null) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNullOrEmpty(String string) {
        if (string == null || (string.trim().length() == 0)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNotNullAndEmpty(String string) {
        if (string != null && (string.trim().length() == 0)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNotNullAndNotEmpty(String string) {
        if (string != null && (string.trim().length() != 0)) {
            return true;
        } else {
            return false;
        }
    }

    //
    public static String nullIfEmpty(String string) {
        if (string == null) {
            return null;
        } else {
            String $ = string.trim();
            if ("".equals($)) {
                return null;
            } else {
                return $;
            }

        }

    }

    public static String emptyIfNull(String string) {
        if (string == null) {
            return "";
        } else {
            return string.trim();
        }

    }

    //
    public static boolean isNull(Object object) {
        if (object == null) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNotNull(Object object) {
        if (object != null) {
            return true;
        } else {
            return false;
        }
    }
    //

    public static boolean isNull(Object[] array) {
        if (array == null) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNull(List<?> list) {
        if (list == null) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNull(Map<String, ?> map) {
        if (map == null) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNull(Set<?> set) {
        if (set == null) {
            return true;
        } else {
            return false;
        }
    }


    //
    public static boolean isHasData(Object[] array) {
        if (array != null && array.length > 0) {
            return true;
        } else {
            return false;
        }

    }

    public static boolean isHasData(List<?> list) {
        if (list != null && list.size() > 0) {
            return true;
        } else {
            return false;
        }

    }

    public static boolean isHasData(Map<String, ?> map) {
        if (map != null && map.size() > 0) {
            return true;
        } else {
            return false;
        }

    }

    public static boolean isHasData(Set<?> set) {
        if (set != null && set.size() > 0) {
            return true;
        } else {
            return false;
        }

    }

}
